package com.yizhuoyan.his.webapi.controller.doctor.outpatient;

import com.yizhuoyan.his.ao.CaseDiagnoseResultAo;
import com.yizhuoyan.his.ao.CaseMedicalRecordAo;
import com.yizhuoyan.his.dto.JSONResponse;
import com.yizhuoyan.his.dto.QueryResult;
import com.yizhuoyan.his.entity.CaseMedicalRecordEntity;
import com.yizhuoyan.his.service.doctor.outpatient.CaseOutpatientMedicalRecordService;
import com.yizhuoyan.his.webapi.controller.doctor.outpatient.vo.CaseOutpatientMedicalRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CaseOutpatientMedicalRecordServiceController {
    @Autowired
    CaseOutpatientMedicalRecordService service;

    @PostMapping("/api/addCaseMedicalRecord")
    public JSONResponse addCaseMedicalRecord(CaseMedicalRecordAo ao) throws Exception {
        service.addCaseMedicalRecord(ao);
        return JSONResponse.ok();
    }
    @PostMapping("/api/addCaseDiagnoseResult")
    public JSONResponse addCaseDiagnoseResult(CaseDiagnoseResultAo ao) throws Exception{
        service.addCaseDiagnoseResult(ao);
        return JSONResponse.ok();
    }


    @PostMapping("/api/queryHistoryCaseByCaseID")
    public JSONResponse queryHistoryCaseByCaseID(String caseID, Integer pageNo, Integer pageSize)throws Exception {
        if(pageNo==null){
            pageNo=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        QueryResult<CaseMedicalRecordEntity> queryResult = service.queryHistoryCaseByCaseID(caseID, pageNo, pageSize);
        QueryResult<CaseOutpatientMedicalRecordVo> queryVoResult = queryResult.rowsMap(CaseOutpatientMedicalRecordVo::of);
        return JSONResponse.ok(queryResult);
    }
    @PutMapping("/api/{id}")
    public JSONResponse modifyDiagnosis(Long id, Integer diagnoseStatus)throws Exception {
        service.modifyDiagnosis(id, diagnoseStatus);
        return JSONResponse.ok();
    }
}
